<?php

class zidianModule extends Model
{
    public function __construct()
    {
        parent::__construct("zidian");
    }

    /**
     * 更新系统自定义词典
     * @date: 2019年6月18日 下午2:26:19
     * @param: variable
     * @return:
     * @author: 龚华尧
     */
    public function UpdateZidian()
    {
        //禁用错误报告
        error_reporting(0);
        //报告运行时错误
        error_reporting(E_ERROR | E_WARNING | E_PARSE);
        //报告所有错误
        error_reporting(E_ALL);

        $list = $this->orderBy("cipin desc")->all();
        $zidianStr = "";
        foreach ($list as $k => $v) {
            $_zidianStr = "{$v["ci"]} {$v["cipin"]} {$v["cixing"]}";
            if ($zidianStr == "") {
                $zidianStr = $_zidianStr;
            } else {
                $zidianStr = $zidianStr . "\r\n" . $_zidianStr;
            }
        }
        // 要写入的文件名字
        $filename = __DIR__ . '/../vendor/fukuball/jieba-php/src/dict/user_dict.txt';

        $myfile = fopen($filename, "w") or die("Unable to open file!");
        $txt = $zidianStr;
        fwrite($myfile, $txt);
        fclose($myfile);
    }

}